package com.pz.cloud.framework.workflow.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pz.cloud.framework.business.workflow.entity.ProcessBind;
import com.pz.cloud.framework.business.workflow.service.IProcessBindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@RestController
@RequestMapping("/workflow/processBind")
@Api(tags = "流程绑定表")
public class ProcessBindController {
    @Autowired
    private IProcessBindService processBindService;
    /**
     * 分页列表查询
     *
     * @param entity
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @AutoLog(value = "流程绑定-分页列表查询")
    @ApiOperation(value = "流程绑定-分页列表查询", notes = "流程绑定-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<ProcessBind>> queryPageList(ProcessBind entity,
                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                   HttpServletRequest req) {
        Result<IPage<ProcessBind>> result = new Result<>();
        QueryWrapper<ProcessBind> queryWrapper = QueryGenerator.initQueryWrapper(entity, req.getParameterMap());
        Page<ProcessBind> page = new Page<>(pageNo, pageSize);
        IPage<ProcessBind> pageList = processBindService.page(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    /**
     * 添加
     * @return
     */
    @AutoLog(value = "流程绑定-添加|编辑")
    @ApiOperation(value = "流程绑定-添加|编辑", notes = "流程绑定-添加|编辑")
    @PostMapping(value = "/add")
    public Result add(@RequestBody ProcessBind entity) {
        Result<ProcessBind> result = new Result<>();
        processBindService.save(entity);
        result.success("保存成功！");
        return result;
    }


    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "流程绑定-通过id删除")
    @ApiOperation(value = "流程绑定-通过id删除", notes = "流程绑定-通过id删除")
    @RequestMapping(value = "/delete",method={RequestMethod.POST,RequestMethod.DELETE})
    public Result delete(@ApiParam(required = true) @RequestParam(name = "id") String id) {
        processBindService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "流程绑定-批量删除")
    @ApiOperation(value = "流程绑定-批量删除", notes = "流程绑定-批量删除")
    @RequestMapping(value = "/deleteBatch",method={RequestMethod.POST,RequestMethod.DELETE})
    public Result deleteBatch(@ApiParam(required = true) @RequestParam(name = "ids") String ids) {
        Result<ProcessBind> result = new Result<>();
        processBindService.removeByIds(Arrays.asList(ids.split(",")));
        result.success("删除成功!");
        return result;
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "流程绑定-通过id查询")
    @ApiOperation(value = "流程绑定-通过id查询", notes = "流程绑定-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<ProcessBind> queryById(@ApiParam(required = true) @RequestParam(name = "id") String id) {
        Result<ProcessBind> result = new Result<>();
        ProcessBind orgSociety = processBindService.getById(id);
        result.setResult(orgSociety);
        result.setSuccess(true);
        return result;
    }

}
